#include "read_thread.h"

read_thread::read_thread( QWaitCondition &cond,QReadWriteLock &lock,QString &m,QObject *parent) :QThread(parent),msg(m),rwlock(lock),cond(cond)
{
    //this->rwlock = lock;
    flag =false;
//    this->msg = m;
}
void read_thread::stop(){
    mutex.lock();
    flag = true;
    mutex.unlock();

}
void read_thread::run(){
    forever{
        mutex.lock();
        if(flag){
            flag =false;
            mutex.unlock();
            break;
        }
        mutex.unlock();
        rwlock.lockForRead();
        cond.wait(&rwlock);//等条件变量，等写线程唤醒
        qDebug() <<this->msg;
        rwlock.unlock();
        //QThread ::sleep(1);
    }
    return;
}
